#include "SNCascadeBoostTrainData.h"
#include "opencv2\core\types_c.h"
#include "opencv2\core\core_c.h"
#include "opencv2\core\internal.hpp"


SNCascadeBoostTrainData::SNCascadeBoostTrainData()
{
}

SNCascadeBoostTrainData::SNCascadeBoostTrainData(const SNFeatureEvaluator* feature_evaluator, const CvDTreeParams& params)
{
	is_classifier = true;
	var_all = var_count = (int)feature_evaluator->getNumFeatures();

	FeatureEvaluator = feature_evaluator;

	shared = true;
	
	set_params(params);
	
	max_c_count = MAX(2, FeatureEvaluator->getMaxCatCount());

	var_type = cvCreateMat(1, var_count + 2, CV_32SC1);
	
	if (FeatureEvaluator->getMaxCatCount() > 0)
	{
		NumPrecalcIdx = 0;
		cat_var_count = var_count;
		ord_var_count = 0;
		for (int vi = 0; vi < var_count; vi++)
		{
			var_type->data.i[vi] = vi;
		}
	}
	else
	{
		cat_var_count = 0;
		ord_var_count = var_count;
		for (int vi = 1; vi <= var_count; vi++)
		{
			var_type->data.i[vi - 1] = -vi;
		}
	}

	var_type->data.i[var_count] = cat_var_count;
	var_type->data.i[var_count + 1] = cat_var_count + 1;

	int max_split_size = cvAlign(sizeof(CvDTreeSplit) + (MAX(0, max_c_count - 33) / 32) * sizeof(int), sizeof(void*));
	int tree_block_size = MAX((int)sizeof(CvDTreeNode)* 8, max_split_size);
	tree_block_size = MAX(tree_block_size + BlockSizeDelta, MinBlockSize);
	tree_storage = cvCreateMemStorage(tree_block_size);
	node_heap = cvCreateSet(0, sizeof(node_heap[0]), sizeof(CvDTreeNode), tree_storage);
	split_heap = cvCreateSet(0, sizeof(split_heap[0]), max_split_size, tree_storage);
}

SNCascadeBoostTrainData::SNCascadeBoostTrainData(const SNFeatureEvaluator* feature_evaluator, int num_samples, int precalc_val_buf_size, int precalc_idx_buf_size, const CvDTreeParams& _params /*= CvDTreeParams()*/)
{
	//SetData(feature_evaluator, num_samples, precalc_val_buf_size, precalc_idx_buf_size, _params);
}


SNCascadeBoostTrainData::~SNCascadeBoostTrainData()
{
}
